package com.touch.jgloo.core;
import java.awt.Color;
import com.sun.opengl.util.texture.Texture;
/** 
 * The JGLTextObject is the abstract object representing 
 * any text that is to be displayed through the use of JGLOO/OWT.
 * It is recommended to use JGLTextObject instead of GLUTText or 
 * JGLText for the added support of compatibility; GLUT may not
 * work under some platforms, therefore JGLText would have to be 
 * used instead of GLUTText. 
 * @author Homicidal Monkey
 * @version 10.1.9
 * @since r461
 * @see com/touch/Licence
 */
public abstract class JGLTextObject extends JGLBase implements JGLRenderable
{			
	private String caption;	
	private char mask;
	private Color color = Color.BLACK;	
	/**
	 * Method used to create a TextObject. Supported types are: TEXTURE and STROKE
	 * @param caption Caption of the TextObject
	 * @param textType Type to use.
	 * @return Returns the JGLTextObject as either GLUTText or JGLText.
	 * @since r461
	 */
	public static JGLTextObject createTextObject(final String caption, final JGLTextType textType)
	{
		//return a new Object based on the type.
		return textType == JGLTextType.TEXTURE ? 
			new TextureText(caption) : textType == JGLTextType.STROKE ?
				new GLUTStrokeText(caption) : null;
	}
	/**
	 * Prevent the creation of a TextObject
	 * @since r461
	 */
	protected JGLTextObject(){}	
	/**
	 * Returns the caption of the TextObject
	 * @return caption as a String
	 * @since r461
	 */
	public final String getCaption()
	{
		//return the Caption
		return this.caption;
	}
	/**
	 * Sets the Mask for the TextObject. 
	 * The masked char will be rendered instead of the text. 
	 * This is used for password fields. 
	 * @param chr Character to mask with.
	 * @since r461
	 */
	public void setMask(final char chr)
	{
		//set the local value for the mask to the char.
		this.mask = chr;
	}
	/**
	 * Returns the char value for the Masked character
	 * @return mask as char.
	 * @since r461
	 */
	public char getMask()
	{
		//returns the local value for the masked character.
		return this.mask;
	}
	/**
	 * Sets the caption of the TextObject
	 * @param cursor pointer of the character which is being set
	 * @param chr character that is being set
	 * @since r461
	 */
	public void setCaption(final int cursor, final char chr)
	{
		//Create an array of characters from the caption
		final char[] caption = this.caption.toCharArray();
		
		//set the character at the specified point
		caption[cursor] = chr;		
		//set the new caption.
		this.setCaption(new String(caption));
	}
	/**
	 * Sets the caption of the TextObject
	 * @param caption String to set the caption to.
	 * @since r461
	 */
	public void setCaption(final String caption)
	{
		//set the local value of the caption to the specified value.
		this.caption = caption;		
	}
	/**
	 * Returns the size of the caption
	 * @return String representing the caption of the Object.
	 * @since r461
	 */
	public final int length()
	{
		//return the local value of the caption.
		return this.caption.length();
	}	
	/**
	 * Sets the color of the TextObject's text
	 * @param color Color to set to.
	 * @since r461
	 */
	public void setColor(final Color color)
	{
		//set the local value for color to the specified value.
		this.color = color;	
	}	
	/**
	 * Returns the color of the TextObject
	 * @return Color object representing the color of the TextObject's caption.
	 * @since r461
	 */
	public final Color getColor()
	{
		//return the Color object
		return this.color;
	}
	/**
	 * Overrides the Object function "toString" and returns the caption.
	 * @return String description of the JGLTextObject.
	 * @since r461
	 */
	public String toString()
	{
		return "TextObject: " + this.caption;
	}
	/**
	 * Sets the texture of the TextObject. Only used for Textured Text Objects.
	 * @param texture Texture to use. Null is accepted as default.
	 * @since r461
	 */
	public void setTexture(final Texture texture) {}
}
